﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Moving03.Services
{
    /// <summary>
    /// Summary description for XemChiTietLoHang
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class XemChiTietLoHang : System.Web.Services.WebService
    {

        DataClasses1DataContext context = new DataClasses1DataContext();
        [WebMethod]
        public classChiTietLoHang[] DanhSachChiTietLoHang(int idmavc)
        {
            
            var query = from ddcn in context.DiaDiemCapNhats
                        join dd in context.DuongDis on ddcn.Id_DDCapNHat equals dd.Id_DDCapNhat
                        where ddcn.Id_ThongTinVanChuyen == idmavc
                        orderby dd.SoThuTu
                        select dd;

            classChiTietLoHang[] arr = new classChiTietLoHang[ query.Count()];
            int stt = 1;
            foreach (var i in query)
            {
                var query2 = (from ddtg in context.DiaDiemTrungGians
                              where ddtg.Id_DDTrungGian == i.Id_DDTGian
                              select ddtg).Single();
                classChiTietLoHang ctlh = new classChiTietLoHang();
                ctlh.DaDen = (int)i.DaToiChua;
                ctlh.NgayToi = i.NgayDen.ToString();
                ctlh.Stt = stt;
                ctlh.NoiToi = query2.TenDiaDiem;
                arr[stt - 1] = (classChiTietLoHang)ctlh;
                stt++;
            }
            return arr;
        }
        [WebMethod]

        public classThongTinDatHang LayThongTinDatHang(int mavc)
        {
            classThongTinDatHang ttdh = new classThongTinDatHang();
            ThongTinVanChuyen ttvc = context.ThongTinVanChuyens.Single(p => p.Id_TTVC == mavc);
            ttdh.DaThanhToan = (int)ttvc.DaThanhToan;
            ttdh.NgayGoi = ttvc.NgayDat.ToString();
            ttdh.NgayToi = ttvc.NgayToi.ToString();
            ttdh.NoiDen = (int)ttvc.IdNoiden;
            ttdh.NoiDi = (int)ttvc.IdNoiDi;
            ttdh.TenLienLacNueSuCo = ttvc.TenNeuSuCo;
            ttdh.ThongTinBiMat1 = ttvc.ThongTinBiMat1;
            ttdh.ThongTinBiMat2 = ttvc.ThongTinBiMat2;
            ttdh.TienTacDongKhiHau = (int)ttvc.TacDongKhiHau;
            ttdh.TenLienLac = ttvc.TenLienLac;
            ttdh.TongTien = (float)ttvc.TongTien;
            ChiTietVanChuyen chitiet = context.ChiTietVanChuyens.Single(p => p.Id_TTVC == mavc);
            ttdh.TienGoi = (float)chitiet.TienGoi;
            ttdh.TienKiGoi = (float)chitiet.TienKiGoi;
            ttdh.TienTacDongKhiHau = (float)chitiet.TienChiuTacDong;

            TinhTrangVanChuyen tt = context.TinhTrangVanChuyens.Single(p => p.Id_TinhTrang == ttvc.TinhTrang);
            ttdh.TinhTrang = tt.TenTinhTrang;

            PhuongThucGoiHang ptgh = context.PhuongThucGoiHangs.Single(p => p.Id_GoiHang == ttvc.Id_PhuongThucGoiHang);
            ttdh.PhuongThucGoiHang = ptgh.LoaiPhat;

            var query = (from a in context.PhuongThucThanhToans
                         where a.Id_ThanhToan == ttvc.Id_PhuongThucThanhToan
                         select a).Single();
            ttdh.PhuongThucThanhToan = query.TenThanhToan;
            return ttdh;
        }        
         
    }
}
